package dummy.virussim

import mars.ns.statechangers.StateChange
import mars.ns.Simulation
import mars.ns.core.Node
import mars.ns.HasState


trait InfectedStateChange[T <: Node with InfectedState] extends StateChange[T] {

  /**
   * If node is infected, it infects all other nodes
   * If a node has a linked object that is infected, it get's infected itself
   */
	override def checkStateChange(node: T,simulation : Simulation[T]) { 
		if(node.isInfected)
		{
			node.getLinkedObjects.foreach(arg =>
				arg match{
		        	case arg : T => { simulation.addEvent(arg,( (n:T) => (n.setInfected)));}
		        	case _ => 
				}
			)
		}else{
			node.getLinkedObjects.foreach(arg =>
				arg match{
		        	case arg : T => { if(arg.isInfected) simulation.addEvent(node,( (n:T) => (n.setInfected)));}
		        	case _ => 
				}
			)
		  
		}
	}
}